package cn.iocoder.yudao.module.wecom.convert.link;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import cn.iocoder.yudao.module.wecom.controller.admin.acqlinkuser.vo.AcqLinkUserRespVO;
import cn.iocoder.yudao.module.wecom.controller.admin.user.vo.WeUserRespVO;
import cn.iocoder.yudao.module.wecom.dal.dataobject.acqlinkuser.AcqLinkUserDO;
import cn.iocoder.yudao.module.wecom.dal.dataobject.customer.WeCustomerDO;
import cn.iocoder.yudao.module.wecom.dal.dataobject.user.WeUserDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.Map;

@Mapper
public interface WeLinkUserConverter {
    WeLinkUserConverter INSTANCE = Mappers.getMapper(WeLinkUserConverter.class);

//    default WeDeptRespVO convert2(WeDeptDO weDeptDO) {
//        WeDeptRespVO respVO = BeanUtils.toBean(weDeptDO, WeDeptRespVO.class);
//        respVO.setId(weDeptDO.getWeDeptId());
//        respVO.setName(weDeptDO.getWeDeptName());
//        return respVO;
//    }

    default PageResult<AcqLinkUserRespVO> convert(PageResult<AcqLinkUserDO> pageResult, Map<String, WeUserDO> userMap, Map<String, WeCustomerDO> customerMap) {
        PageResult<AcqLinkUserRespVO> result = BeanUtils.toBean(pageResult, AcqLinkUserRespVO.class);
        result.getList().forEach(r -> {
            MapUtils.findAndThen(userMap, r.getWeUserId(), (rs) -> {r.setWeUserName(rs.getNickname()); });
            MapUtils.findAndThen(customerMap, r.getWeCustomerId(), (rs) -> {r.setWeCustomerName(rs.getName()); });
        });
        return result;
    }
}
